import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import Home from '../views/Home.vue'
import Welcome from '../views/Welcome.vue'
import Users from '../components/Users.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'login',
    component: Login
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/home',
    name: 'home',
    component: Home ,
    redirect :'/welcome',
    childer:[
      { path : '/welcome' , component : Welcome},
      { path : '/users' , component : Users}
    ]
  }
]

const router = new VueRouter({
  routes
})
//挂载路由导航首位
//router.beforeEach((to,from,next) =>{
//to将要访问的地址
//from代表从那个路径跳转而来
//next是一个函数，表示放行
//next()放行 next('/login')强制跳转
// if(to.path==='/login') return next()
//获取token
// const mytoken = window.sessionStorage.getItem("token")
//if(!mytoken) return next('/login')
//})
export default router
